package com.general.framework.data.redis;

import org.redisson.api.RedissonClient;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *
 */
@Component
public class RedisCachePlus {

    @Resource
    protected RedissonClient redissonClient;

    /**
     * 获取并设置值
     * @param key
     * @param num
     * @return
     */
    public long getAndSet(final String key, final Long num) {
        return redissonClient.getAtomicLong(key).getAndSet(num);
    }

    /**
     * 增加1后获取值
     * @param key 缓存key
     * @return
     */
    public long incrementAndGet(final String key) {
        return redissonClient.getAtomicLong(key).incrementAndGet();
    }

    /**
     * 获取后增加1
     * @param key 缓存key
     * @return
     */
    public long getAndIncrement(final String key) {
        return redissonClient.getAtomicLong(key).getAndIncrement();
    }

    /**
     * 减1后获取值
     * @param key 缓存key
     * @return
     */
    public long decrementAndGet(final String key) {
        return redissonClient.getAtomicLong(key).decrementAndGet();
    }

    /**
     * 获取后减1
     * @param key 缓存key
     * @return
     */
    public long getAndDecrement(final String key) {
        return redissonClient.getAtomicLong(key).getAndDecrement();
    }

    /**
     * 获取后加值
     * @param key 缓存key
     * @return
     */
    public long getAndAdd(final String key, final long delta) {
        return redissonClient.getAtomicLong(key).getAndAdd(delta);
    }

}
